package vivo.com.foolishbar.core.warp.page;

import com.google.inject.name.Named;
import com.wideplay.warp.annotations.OnEvent;
import com.wideplay.warp.annotations.URIMapping;
import com.wideplay.warp.annotations.event.PreRender;
import com.wideplay.warp.persist.Transactional;
import com.wideplay.warp.persist.dao.Finder;

// use a RESTful idiom. 
@URIMapping("/blog/{id}")
public class ViewBlog {

	private Blog blog;

	// @Inject
	// @Page
	// private ListBlogs listBlogs;

	// @OnEvent
	// @PreRender
	// public void init(String subject) {
	// this.blog = listBlogs.getBlog(subject);
	// }

	@Finder(query = "from Blog where id = :id")
	Blog fetchBlog(@Named("id") Long id) {
		return null;
	}

	@OnEvent
	@PreRender
	@Transactional
	public void onView(String id) {
		this.blog = fetchBlog(Long.valueOf(id)); // dangerous, validate id first!
	}

	/*
	 * Getter and Setters
	 */
	public Blog getBlog() {
		return blog;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

}
